package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import java.util.ArrayList;

public abstract class ArrayDialogAdapter<T> extends BaseAdapter {

  private ArrayList<T> objects = new ArrayList<>();
  private LayoutInflater layoutInflater;

  protected ArrayDialogAdapter(ArrayList<T> obj, Context context) {

    this.objects = obj;
    this.layoutInflater = LayoutInflater.from(context);
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {

      convertView = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
      convertView.setTag(new ViewHolder(convertView));
    }
    initializeViews(getItem(position), ((ViewHolder) convertView.getTag()).tvName);
    return convertView;
  }

  public abstract void initializeViews(T object, TextView tv);

  //SettlementInfo item = (SettlementInfo) object;
  //holder.tvNameSettlementInfo.setText(item.getName());
  //holder.tvCostSettlementInfoItem.setText(String.valueOf(item.getCost())+"元");
  //holder.tvDateSettlementInfo.setText(item.getDate());

  @Override public boolean isEmpty() {
    return false;
  }

  public static class ViewHolder {

    @BindView(android.R.id.text1) TextView tvName;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}
